const User = require('./model/User.js')
const Goods = require('./model/Goods.js')
const Category = require('./model/Category')
const CategorySub = require('./model/CategorySub')
const Banner = require('./model/Banner')
const Order = require('./model/Order')
const UserAddress = require('./model/UserAddress')


Category.hasMany(CategorySub,{
    foreignKey:'MALL_CATEGORY_ID',
    targetKey:'id'
})


Category.belongsToMany(Goods,{
    through:'CategorySub',
    foreignKey:'MALL_CATEGORY_ID',
    targetKey:'SUB_ID',
    otherKey:'PID'
})




Order.belongsTo(Goods,{
    foreignKey:'goods_pid',
    targetKey:'PID'
})




CategorySub.hasMany(Goods,{
	foreignKey:'SUB_ID',
	targetKey:'PID'
})

Goods.belongsTo(CategorySub,{
	foreignKey:'SUB_ID',
	targetKey:'PID'
})



UserAddress.hasMany(User,{
	foreignKey:'openid',
	targetKey:'user_id'
})



module.exports={
    User,
    Goods,
    Category,
    CategorySub,
    Banner,
    Order,
	UserAddress
}